import Configer from "../../../script/frame/apiModel/config/Configer";
import {UIConfigKey} from "../../../script/constant/UIConfig";
import * as React from "../../../script/frame/apiModel/gui/React";
import {IProps, View} from "../../../script/frame/apiModel/gui/React";
import {GuiKeys} from "../../../script/controller/model/ControllerOpt";
import PercentBar from "../component/PercentBar";
import {BossLifeBarInterface} from "../../interface/GuiInterface";
import {ResourceKey} from "../../../script/constant/ResourceConstant";

interface IProp {
}
interface IState {
    max: number,
    current: number,
}
export default class BossLifeBar extends BossLifeBarInterface<IProp, IState> {
    constructor(props: IProps & IProp) {
        super(props);
        this.state = {
            visible: false,
            max: 0,
            current: 0,
        }
    }


    render = () => {
        const lifeBar = Configer.getResource(ResourceKey.lifeBar);
        const lifeBarBack = Configer.getResource(ResourceKey.lifeBarBack);
        const fontSize = Configer.getUIConfig(UIConfigKey.fontSize);
        const backSize = { h: 0.03320, w: 0.50000 };
        const backPos = { x: 0.25000, y: 0.11620 };

        let maxValue = this.state.max;
        let value = this.state.current;


        return <View   key = {`${GuiKeys.bossLifeBar}`}  style={{ hidden: !this.state.visible, left: backPos.x, top: backPos.y, width: backSize.w, height: backSize.h }}>
            <PercentBar   key={`${GuiKeys.bossLifePercentBar}`} fontSize={fontSize} marginT={0.00498} max={maxValue} current={value} back={lifeBarBack} line={lifeBar} width={backSize.w} height={backSize.h} showPercent={true}></PercentBar>
        </View>
    }

    canel = () => {
        this.setState({
            ...this.state,
            visible: false,
        })
    }

    reflushBar = (life: number, maxLife: number) => {
        let visible = false;
        if (maxLife > 0) {
            visible = true
        }
        this.setState({
            ...this.state,
            visible: visible,
            current: life,
            max: maxLife,
        })
    }
    getVisible = () => {
        return this.state.visible
    };
}